#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> maze(n, vector<int>(m));
  for (auto &row : maze) for (auto &x : row) cin >> x;

  vector<vector<int>> dp(n, vector<int>(m, -1));
  constexpr pair<int, int> dirs[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  auto dfs = [&](auto &self, int x, int y) {
    int &res = dp[x][y];
    if (res != -1) return res;
    res = 1;
    for (auto [dx, dy] : dirs) {
      int nx = x + dx, ny = y + dy;
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (maze[nx][ny] <= maze[x][y]) continue;
      res = max(res, self(self, nx, ny) + 1);
    }
    return res;
  };
  int ans = 0;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      ans = max(ans, dfs(dfs, i, j));
    }
  }
  cout << ans << endl;
}